home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / human interface toolbox / labelmenu / initmac.c next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  4.2 KB  |  156 lines

  1. /*
  2.     File:        InitMac.c
  3.  
  4.     Contains:    This demonstrates a program with a Finder-like label menu.
  5.                 Each label menu item has a 12x16 pixel 'cicn and the
  6.                 color and name of all the items are updated if the user
  7.                 changes anything in the "Labels" control panel.
  8.                 This also demonstrates how to change a menu tile to an icon.
  9.  
  10.     Written by: David Hayward    
  11.  
  12.     Copyright:    Copyright © 1993-1999 by Apple Computer, Inc., All Rights Reserved.
  13.  
  14.                 You may incorporate this Apple sample source code into your program(s) without
  15.                 restriction. This Apple sample source code has been provided "AS IS" and the
  16.                 responsibility for its operation is yours. You are not permitted to redistribute
  17.                 this Apple sample source code as "Apple sample source code" after having made
  18.                 changes. If you're going to re-distribute the source, we require that you make
  19.                 it clear in the source that the code was descended from Apple sample source
  20.                 code, but that you've made changes.
  21.  
  22.     Change History (most recent first):
  23.                 8/6/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  24.                 4/8/94                          updated project to use the new Universal Header
  25.                                               added routine to change a menu title
  26.                                             added abillity to change Label menu's title to a
  27.                                             small icon (for info on how this is done see IM:Text
  28.                                             page 7-39
  29.  
  30. */    
  31.  
  32.  
  33. #include <Dialogs.h>
  34. #include <Memory.h>
  35. #include <Windows.h>
  36. #include <QuickDraw.h>
  37. #include <Fonts.h>
  38. #include <GestaltEQU.h>
  39. #include <Traps.h>
  40. #include <TextEdit.h>
  41. #include <OSUtils.h>
  42.  
  43. #include "InitMac.h"
  44.  
  45. #define TrapMask 0x0800
  46.  
  47.  
  48. /**\
  49. |**| ==============================================================================
  50. |**| GLOBALS
  51. |**| ==============================================================================
  52. \**/
  53. SysEnvRec    TheWorld;
  54. Boolean        WNE_available;
  55. Boolean        HasGWorlds;
  56. Boolean        HasCQD;
  57.  
  58.  
  59.  
  60. /*------------------------------------------------------------------------------*\
  61.     NumToolboxTraps
  62. \*------------------------------------------------------------------------------*/
  63. short NumToolboxTraps (void)
  64. {
  65.     if (NGetTrapAddress(_InitGraf, ToolTrap) ==
  66.             NGetTrapAddress(0xAA6E, ToolTrap))
  67.         return(0x0200);
  68.     else
  69.         return(0x0400);
  70. }
  71.  
  72.  
  73. /*------------------------------------------------------------------------------*\
  74.     GetTrapType
  75. \*------------------------------------------------------------------------------*/
  76. TrapType GetTrapType (short theTrap)
  77. {
  78.     if ((theTrap & TrapMask) > 0)
  79.         return(ToolTrap);
  80.     else
  81.         return(OSTrap);
  82. }
  83.  
  84.  
  85. /*------------------------------------------------------------------------------*\
  86.     TrapAvailable
  87. \*------------------------------------------------------------------------------*/
  88. Boolean TrapAvailable (short theTrap)
  89. {
  90.  
  91.     TrapType    tType;
  92.  
  93.     tType = GetTrapType(theTrap);
  94.     if (tType == ToolTrap)
  95.         theTrap &= 0x07FF;
  96.     if (theTrap >= NumToolboxTraps())
  97.         theTrap = _Unimplemented;
  98.  
  99.     return (NGetTrapAddress(theTrap, tType) !=
  100.             NGetTrapAddress(_Unimplemented, ToolTrap));
  101. }
  102.  
  103.  
  104. /*------------------------------------------------------------------------------*\
  105.     WNEAvailable
  106. \*------------------------------------------------------------------------------*/
  107. Boolean WNEAvailable (void)
  108. {
  109.     return TrapAvailable(_WaitNextEvent);
  110. }
  111.  
  112.  
  113. /*------------------------------------------------------------------------------*\
  114.     CheckQuickDraw
  115. \*------------------------------------------------------------------------------*/
  116. void CheckQuickDraw (void)
  117. {
  118.     long      QDvers;  /* Version of QuickDraw on this machine */
  119.     
  120.     /* Find out if GWorlds and CQD are implemented on this machine */
  121.     Gestalt(gestaltQuickdrawVersion, &QDvers);
  122.  
  123.     HasGWorlds = (QDvers > gestaltOriginalQD && QDvers < gestalt8BitQD)
  124.                   || QDvers >= gestalt32BitQD;
  125.     
  126.     HasCQD = (QDvers >= gestalt8BitQD);
  127. }
  128.  
  129.  
  130. /*------------------------------------------------------------------------------*\
  131.     InitToolBox
  132. \*------------------------------------------------------------------------------*/
  133. void InitToolBox (short numberOfMasters)
  134. {
  135.     
  136.     InitGraf((Ptr) &qd.thePort);
  137.     InitFonts();
  138.     InitWindows();
  139.     InitMenus();
  140.     InitCursor();
  141.     TEInit();
  142.     FlushEvents(everyEvent, 0);
  143.     InitDialogs(nil);
  144.     
  145.     while(numberOfMasters--)
  146.         MoreMasters();
  147.         
  148.     MaxApplZone();
  149.     
  150.     SysEnvirons(1,&TheWorld);
  151.     
  152.     WNE_available = WNEAvailable();
  153.  
  154.     CheckQuickDraw ();
  155. }
  156.